package com.atguigu.com.nio.nio_1_buffer;

import java.nio.ByteBuffer;

/**
 * @Author: robert.song
 * @Date: Created in 2021/8/7
 */
public class NIOBufferPutGet {
    public static void main(String[] args) {
//        创建一个buffer
        ByteBuffer buffer = ByteBuffer.allocate(64);
//        类型化方式放入数据
        buffer.putInt(100);
        buffer.putInt(9);
        buffer.putChar('哈');
        buffer.putShort((short) 10);
//        取出
        buffer.flip();

        System.out.println(buffer.getInt());
        System.out.println(buffer.getInt());
        System.out.println(buffer.getChar());
//      下面报java.nio.BufferUnderflowException，因为put的是short,而取出的是long，导致position越过了limit
        System.out.println(buffer.getLong());
    }
}
